// 二次对wx.request进行封装
import config from './config'
import {showToast}from './tips'
export default function ({url,method="GET",data={}}){
    return new Promise((resolve,reject)=>{
      wx.showLoading({
        title:'加载中..',
      })
      const header = { 
        'content-type': 'application/json' // 默认值
      }
      const token = wx.getStorageSync('token')
      token && (header.token = token)
      wx.request({
        url:config.baseUrl + url,
        method,
        data,
        header,
        success(res){
        // console.log('res11',res)
          wx.hideLoading()
          if(res.data.code === 200 ){
            resolve(res.data)
          }else{
            reject(res.data.data)
          }
        },
        fail(error){
          wx.hideLoading()
          showToast('请求失败')
          reject(error)
        }
      })
    })
}
